<template>
  <div>
    <el-table-form ref="form" class="form" :model="query">
      <el-form-item label="所属机构:" class="merge-item">
        <el-tree-select
          v-model="query.orgSNNo"
          :clearable="false"
          class="tree-select"
          :popover-width="360"
          :select-params="{
            clearable: true,
            placeholder: '请选择',
            loading: $loadingPlugin.getTreeData,
          }"
          :tree-params="{
            'expand-on-click-node': false,
            'highlight-current': true,
            'filterable': true,
            props: {
              value: 'orgSNNo',
              label: 'orgName',
              disabled: 'disabled',
            },
            data: treeData,
          }"
          @node-click="selectTreeChange"
        />
      </el-form-item>
      <el-form-item :table-form-merge="0.2">
        <el-checkbox v-model="query.option" label="包含下级" />
      </el-form-item>
      <!-- <el-form-item label="处理人:" class="merge-item">
        <el-select v-model="query.checkUserIdList" filterable multiple collapse-tags clearable placeholder="请选择">
          <el-option
            v-for="item in checkUserMap"
            :key="item.userId"
            :label="item.userName"
            :value="item.userId"
          />
        </el-select>
      </el-form-item> -->
      <el-form-item class="merge-item" :table-form-merge="1.4">
        <el-select v-model="userType" style="width: 260px; margin-right: 2px;" @change="getCheckUser">
          <el-option label="安检人" value="securityUserIdList" />
          <el-option label="最后转派接收人" value="checkUserIdList" />
          <el-option label="最后复检员" value="recheckUserIdList" />
        </el-select>
        <el-select v-model="userValue" filterable multiple collapse-tags clearable placeholder="请选择">
          <el-option
            v-for="item in checkUserMap"
            :key="item.userId"
            :label="item.userName"
            :value="item.userId"
          />
        </el-select>
      </el-form-item>
      <el-form-item class="merge-item">
        <el-select v-model="qtype" style="width: 180px; margin-right: 2px;">
          <el-option label="复检单号" value="recheckbillCode" />
          <el-option label="安检单号" value="checkId" />
          <el-option label="整改单号" value="tracecode" />
          <el-option label="客户编号" value="csmCode" />
          <el-option label="客户名称" value="csmName" />
          <el-option label="联系电话" value="csmPhone" />
        </el-select>
        <el-input v-model.trim="param" clearable placeholder="请输入" />
      </el-form-item>
      <el-form-item label="隐患等级:" prop="warnLevel">
        <el-select v-model="query.warnLevel" filterable clearable placeholder="请选择">
          <el-option
            v-for="item in warnLevelMap"
            :key="item.value"
            :label="item.desc"
            :value="item.value"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="状态:" prop="recheckStatus">
        <el-select v-model="query.recheckStatus" filterable clearable placeholder="请选择">
          <el-option
            v-for="item in checkStatusMap"
            :key="item.value"
            :label="item.desc"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item :table-form-merge="2" class="merge-item">
        <el-select v-model="timeType" style="width: 170px; margin-right: 2px;">
          <el-option label="安检时间" value="checkDt" />
          <el-option label="最后复检时间" value="lastCheckTime" />
        </el-select>
        <el-date-picker
          v-model="date"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          unlink-panels
          clearable
          value-format="yyyy-MM-dd"
        />
      </el-form-item>
      <el-form-item label="下单限制:">
        <el-select v-model="query.isClosed" filterable clearable placeholder="请选择">
          <el-option
            v-for="item in [{desc:'关闭',value:-1},{desc:'生效',value:1}]"
            :key="item.value"
            :label="item.desc"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="安检单类别:">
        <el-select v-model="query.isAudit" clearable placeholder="请选择">
          <el-option
            v-for="item in isAuditMap"
            :key="item.value"
            :label="item.desc"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="所属区域:">
        <el-select v-model="query.countryCode" clearable placeholder="请选择" @change="getStreetlist">
          <el-option
            v-for="item in areaData"
            :key="item.value"
            :label="item.desc"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="所属街道:">
        <el-select v-model="query.streetCode" clearable placeholder="请选择">
          <el-option
            v-for="item in streetlist"
            :key="item.value"
            :label="item.desc"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <template v-slot:btns>
        <el-button
          v-permission="[60105, 1]"
          type="primary"
          icon="el-icon-search"
          :loading="$loadingPlugin.fetchData"
          @click="search"
        >查询</el-button>
      </template>
    </el-table-form>
    <div style="margin-bottom: 10px;" class="btn-group">
      <el-button
        v-permission="[60105, 2]"
        type="primary"
        icon="el-icon-s-platform"
        :disabled="disabled"
        @click="transfer"
      >转派</el-button>
      <el-button
        v-permission="[60105, 3]"
        type="primary"
        icon="el-icon-s-check"
        :disabled="recheckDisabled"
        @click="reCheck"
      >复检核查</el-button>
      <el-button
        v-permission="[60105, 4]"
        type="primary"
        icon="el-icon-remove"
        :disabled="disabledLimit"
        @click="limitOrder"
      >限制下单</el-button>
      <el-button
        v-permission="[60105, 5]"
        type="primary"
        icon="el-icon-download"
        @click="batchExp"
      >导出</el-button>
    </div>
    <lb-table
      ref="lbTable"
      v-loading="$loadingPlugin.fetchData"
      v-el-height-adaptive-table="{ bottomOffset: 10 }"
      border
      element-loading-text="加载中"
      :column="column"
      :data="tableData.data"
      pagination
      :total="tableData.total"
      custom-column
      @fetch="fetchData"
      @selection-change="handleSelectionChange"
    />
    <securityOrderInfo
      ref="securityOrderInfo"
      :tree-data="treeData"
      :index-table-data="tableData.data"
      :warn-level-map="warnLevelMap"
      :parent-fetch-data="refresh"
    />
    <csm-detail ref="csmDetail" :parent-fetch-data="refresh" :tree-data="treeData" :calc-type-list="calcTypeList" :paymen-fil-list="paymenFilList" />
    <rectification ref="rectification" />
    <reCheck ref="reCheck" :parent-fetch-data="refresh" />
    <transfer ref="transfer" :parent-fetch-data="refresh" />
    <exchange ref="exchange" />
    <order-detail ref="orderDetail" />
  </div>
</template>

<script>
  import securityOrderInfo from '../../securityOrderManage/components/securityOrderInfo.vue'
  import reCheck from './reCheck.vue'
  import transfer from './transfer.vue'
  import exchange from './exchange.vue'
  import CsmDetail from '../../../components/CsmDetailModal/index.vue'
  import rectification from '../../securityOrderManage/components/rectification.vue'
  import getTreeData from '@/utils/jsonTree'
  import { mapGetters } from 'vuex'
  import { formatColumnMap, parseTime } from '@/utils'
  import { mergeAsyncFunc } from '@/utils/mergeAsyncFunc'
  import {
    gasCheckBillExportAgain,
    gasCheckBillReverse,
    gasCheckItemList,
    queryRiskTrackMap,
    recheckQueryList,
    restrictOrders,
    queryMap,
    csDeliverUserList,
    selectAreaCode
  } from '@/api'
  import moment from 'dayjs'
  export default {
    name: 're-inspection',
    components: { rectification, securityOrderInfo, reCheck, transfer, exchange, CsmDetail,
                  OrderDetail: () => import('../../../orderCenter/orderManage/components/OrderDetails.vue')
    },
    data() {
      return {
        qtype: 'recheckbillCode',
        timeType: 'checkDt',
        userType: 'securityUserIdList',
        userValue: '',
        param: '',
        actionColWidth: 80,
        mode: 1,
        treeData: [],
        gasCheckItemArray: [],
        txt: '',
        checkUserMap: [],
        multipleSelection: [],
        calcTypeList: [],
        paymenFilList: [],
        areaData: [],
        streetlist: [],
        warnLevelMap: [
          { value: 1, desc: '停止供气', key: 'STOPGAS' },
          { value: 2, desc: '限期整改', key: 'XQZG' },
          { value: 3, desc: '立即整改', key: 'LJZG' },
          { value: 4, desc: '有隐患', key: 'YYH' },
          { value: 5, desc: '未安装报警器', key: 'WAZ' },
          { value: 6, desc: '无隐患', key: 'WYH' }
        ],
        checkStatusMap: [
          { value: 1, desc: '待核查', key: 'ToBeChecked' },
          { value: 2, desc: '通过', key: 'Pass' },
          { value: 3, desc: '不通过', key: 'UN_pass' },
          { value: -1, desc: '失效', key: 'INVALID' }
        ],
        isClosedMap: [
          { value: 0, desc: '关闭' },
          { value: 1, desc: '生效' }
        ],
        checkTypeMap: [
          { value: 1, desc: '随单安检', key: 'SD' },
          { value: 2, desc: '定期安检', key: 'JH' }
        ],
        date: [],
        isAuditMap: [],
        query: {
          recheckStatus: '',
          orgType: 'security',
          csmTypes: [1, 2, 4],
          orgSNNo: '',
          imageName: 'all',
          checkDt: '',
          checkDtEnd: '',
          option: false,
          checkUserIdList: [],
          isClosed: null,
          isAudit: 1,
          countryCode: '',
          streetCode: ''
        },
        roleTypeList: [],
        searchParams: {},
        tableData: {
          total: 0,
          data: []
        },
        selectRowIndex: null,
        disabled: true,
        recheckDisabled: true,
        disabledLimit: true
      }
    },
    computed: {
      ...mapGetters(['orgList', 'exportDomain', 'userInfo']),
      column: function() {
        return [
          {
            type: 'index'
          },
          {
            type: 'selection'
          },
          {
            label: '下单限制',
            prop: 'isClosed',
            render: (h, { row }) => (
            <span>
              {formatColumnMap(this.isClosedMap, 'value', row.isClosed, 'desc')}
            </span>
          )
          },
          { label: '复检单号', width: 100, prop: 'recheckbillCode',
            render: (h, { row }) => (
              <el-link
                  size='mini'
                  underline={false}
                  onClick={() => this.openOrderInfo(row, '复检详情')}
                >
                  {row.recheckbillCode}
                </el-link>
          )
          },
          {
            label: '生成时间',
            width: 160,
            prop: 'createTime',
            render: (h, { row }) => (
            <span>
              {row.createTime && parseTime(row.createTime, '{y}-{m}-{d} {h}:{i}:{s}')}
            </span>
          )
          },
          { label: '用户所属机构', width: 130, prop: 'nearStationName' },
          {
            label: '客户编号',
            prop: 'csmCode',
            width: 100,
            render: (h, { row }) => <el-link underline={false} onClick={() => this.openCsmDetail(row)}>{row.csmCode}</el-link>
          },
          { label: '客户名称', prop: 'csmName' },
          {
            label: '所属区域',
            align: 'center',
            prop: 'countryName'
          },
          {
            label: '所属街道',
            align: 'center',
            prop: 'streetName'
          },
          { label: '联系地址', width: 150, prop: 'csmAddress' },
          { label: '联系电话', width: 150, prop: 'csmPhone' },
          { label: '关联安检单',
            width: 150,
            prop: 'checkId',
            render: (h, { row }) => (
              <el-link
                  size='mini'
                  underline={false}
                  onClick={() => this.openOrderInfo(row, '安检单详情')}
                >
                  {row.checkId}
                </el-link>
          ) },
          { label: '安检人', width: 120, prop: 'checkUser' },
          // { label: '关联订单号',
          //   width: 110,
          //   prop: 'orderCode',
          //   render: (h, { row }) => (
          //       <el-link
          //         size='mini'
          //         underline={false}
          //         onClick={() => this.openOrderDetail(row)}
          //       >
          //         {row.orderCode}
          //       </el-link>
          // )
          // },
          {
            label: '安检单类别',
            align: 'center',
            prop: 'isAudit',
            render: (h, { row }) => (
            <span>
              {row.isAudit &&
                formatColumnMap(this.isAuditMap, 'value', row.isAudit, 'desc')}
            </span>
          )
          },
          {
            label: '隐患等级',
            align: 'center',
            width: 160,
            prop: 'warnLevel',
            render: (h, { row }) =>
              row.warnLevel ? (
              <el-link underline={false} onClick={() => this.warnInfo(row)}>
                {formatColumnMap(this.warnLevelMap, 'value', row.warnLevel, 'desc')}
              </el-link>
                ) : (
              <span>
                {formatColumnMap(this.warnLevelMap, 'value', row.warnLevel, 'desc')}
              </span>
            )
          },
          { label: '隐患数',
            width: 80,
            prop: 'warnCount'
          },
          {
            label: '关联整改单',
            width: 130,
            prop: 'traceCode',
            render: (h, { row }) => (
              <el-link
                  size='mini'
                  underline={false}
                  onClick={() => this.openOrderInfo(row, '整改详情')}
                >
                  {row.traceCode}
                </el-link>)
          },
          { label: '最后转派接收人', prop: 'checkUserName' },
          {
            label: '复检状态',
            align: 'center',
            prop: 'recheckStatus',
            render: (h, { row }) => (
            <span>
                {formatColumnMap(this.checkStatusMap, 'value', row.recheckStatus, 'desc')}
            </span>
          ) },
          {
            label: '复检次数',
            align: 'center',
            prop: 'recheckcount'
          },
          { label: '最后复检员', width: 120, prop: 'lastCheckUserName' },
          {
            label: '最后复检时间',
            width: 160,
            prop: 'lastCheckTime',
            render: (h, { row }) => (
            <span>
              {row.lastCheckTime && parseTime(row.lastCheckTime, '{y}-{m}-{d} {h}:{i}:{s}')}
            </span>
          )
          },
          { label: '备注', width: 100, prop: 'remark' }
          // {
          //   label: '安检类型',
          //   prop: 'checkType',
          //   minWidth: 110,
          //   render: (h, { row }) => (
          //   <span>
          //     {row.checkType ? formatColumnMap(this.checkTypeMap, 'value', row.checkType, 'desc') : ''}
          //   </span>
          //   )
          // }
          // {
          //   label: '操作',
          //   className: 'action-col',
          //   width: this.actionColWidth,
          //   fixed: 'right',
          //   render: (h, { row, $index }) => {
          //     return (
          //     <div>
          //       {(
          //         <el-link
          //           v-permission='25'
          //           size='mini'
          //           underline={false}
          //           onClick={() => this.openOrderExamine(row, $index)}
          //         >
          //           流转信息
          //         </el-link>
          //       )}
          //     </div>
          //     )
          //   }
          // }
        ]
      }
    },
    watch: {
      'query.orgSNNo': function(val) {
        this.queryGasCheckItem()
      },
      'query.checkType': function(val) {
        this.queryGasCheckItem()
      },
      'query.csmTypes': function(val) {
        this.queryGasCheckItem()
      }
    },
    async created() {
      // 初始化查询时间
      this.date = [moment(new Date(new Date().getTime() - 24 * 60 * 60 * 1000)).format('YYYY-MM-DD'),
                   moment(new Date()).format('YYYY-MM-DD')]
      await this.getTreeData()
      this.getdanger()
      this.queryOptionsMap()
      this.getAreaData()
    },
    methods: {
      async getdanger() {
        // presetDicQueryList
        const res = await queryRiskTrackMap()
        const data = JSON.parse(res.data.warnLevel) // 隐患等级
        if (data) {
          this.warnLevelMap = []
          data.forEach(item => {
            this.warnLevelMap.push({
              value: item.keyVal,
              desc: item.keyName
            })
          })
        }
      },
      // 获取区域
      async getAreaData() {
        const res = await selectAreaCode({ areaCode: this.userInfo.cityCode })
        this.areaData = res.data.map(item => {
          return {
            value: item.areaCode,
            desc: item.areaName
          }
        })
      },
      async getStreetlist() {
        this.query.streetCode = ''
        const res = await selectAreaCode({ areaCode: this.query.countryCode })
        this.streetlist = res.data.map(item => {
          return {
            value: item.areaCode,
            desc: item.areaName
          }
        })
      },
      // 查询枚举
      async queryOptionsMap() {
        const [res1, res2, res3] = await Promise.all([
          mergeAsyncFunc(queryMap, { enumName: 'CalcType' }),
          mergeAsyncFunc(queryMap, { enumName: 'PaymentMethod' }),
          mergeAsyncFunc(queryMap, { enumName: 'GasAuditType' })
        ])
        this.calcTypeList = res1.data // 收款方式
        // 过滤支付方式
        const arr = ['现金', '微信支付', '支付宝', '银行支付']
        res2.data.filter(item => {
          if (arr.includes(item.desc)) {
            this.paymenFilList.push(item)
          }
        })
        this.isAuditMap = res3.data // 安检单类别
      },
      // 获取所属机构数据
      async getTreeData() {
        const data = this.orgList.map((item) => ({
          label: item.name,
          ...item
        }))
        this.treeData = getTreeData(data)
        this.query.orgSNNo = this.orgList && this.orgList[0].orgSNNo
        this.query.orgId = this.orgList && this.orgList[0].orgId
        this.getCheckUser(this.query.orgId)
      },
      // 选择所属机构
      selectTreeChange(value) {
        this.query.orgSNNo = value.orgSNNo
        this.query.orgId = value.orgId
        this.getCheckUser(value.orgId)
        this.$refs.lbTable.fetch({ currentPage: 1 })
      },
      _getQuery(obj) {
        const query = {}
        for (const key in obj) {
          if (obj.hasOwnProperty(key)) {
            if (obj[key] !== '') {
              query[key] = obj[key]
            }
          }
        }
        query.orgId = this.query.option ? 0 : this.query.orgId
        query.isAudit = !this.query.isAudit ? -1 : this.query.isAudit
        return query
      },

      async fetchData({ currentPage, pageSize }) {
        const query = await this.getQuery()
        console.log('query', query)
        if (this.param) {
          query[this.qtype] = this.param
        }
        if (query.warnLevel === 0) query.warnLevel = -1
        query.pageIndex = currentPage
        query.pageSize = pageSize
        query[this.userType] = this.userValue
        const res = await recheckQueryList(query)
        this.searchParams = query
        this.tableData.data = res.data.rows
        if (currentPage === 1) this.tableData.total = res.data.total
        this.flexColumnWidth()
      },
      radioChange(value) {
        this.query.imageName = value
        this.$refs.lbTable.fetch()
      },
      // 安检人
      async getCheckUser() {
        this.userValue = []
        const param = {
          deliveryOrgId: this.query.orgId || -1,
          deliveryOrgSNNo: this.query.orgSNNo,
          utypeList: this.userType === 'securityUserIdList' ? [2048] : (this.userType === 'checkUserIdList' || this.userType === 'recheckUserIdList') ? [16384] : []
        }
        const res = await csDeliverUserList(param)
        this.checkUserMap = res.data
      },
      queryGasCheckItem() {
        let val
        if (this.query.csmTypes && this.query.csmTypes.length) {
          val = this.query.csmTypes.reduce((prev, cur, index, array) => {
            return prev + cur
          })
        }
        gasCheckItemList({
          orgSNNo: this.query.orgSNNo,
          csmType: val,
          checkType: this.query.checkType
        }).then((res) => {
          const gasCheckItemArray = res.data
          gasCheckItemArray.map((item) => {
            item.detailList.map((item2) => {
              item2.label = item2.itemDetailName
              item2.value = item2.itemDetailId
            })
            item.children = item.detailList
            item.label = item.itemName
            item.value = item.itemId
          })
          if (!this.query.csmTypes.length) {
            this.gasCheckItemArray = []
          } else {
            this.gasCheckItemArray = gasCheckItemArray
          }
        })
      },
      changType(val) {
        if (!val.length) this.gasCheckItemArray = []
      },
      changeChecktype() {
        if (!this.query.csmTypes.length) this.gasCheckItemArray = []
      },
      // 打开关联订单
      async openOrderDetail(row) {
        await this.$refs.orderDetail.open(row, true)
      },
      revokeExamine(row) {
        this.$confirm(`本操作将清空该地址的最后一次安检时间，是否继续？`, '操作提示', {
          type: 'warning'
        }).then(() => {
          gasCheckBillReverse({
            checkIds: row.checkId
          }).then((res) => {
            if (res.success) {
              this.$message({
                message: '操作成功!',
                type: 'success'
              })
              this.search()
            } else {
              this.$message({
                message: '操作失败！',
                type: 'error'
              })
            }
          })
        })
      },
      // 复核
      reCheck() {
        const recheckbillCodes = this.multipleSelection.map((item) => item.recheckbillCode)
        const codes = recheckbillCodes.join(',')
        this.$refs.reCheck.open(codes)
      },
      // 隐患详情
      warnInfo(row) {
        this.$refs.rectification.open(row)
      },
      // 导出
      batchExp() {
        const _this = this
        this.$confirm(`确定导出数据？`, '提示', {
          type: 'warning'
        }).then(() => {
          const copyColumn = JSON.parse(JSON.stringify(this.column))
          copyColumn.splice(14, 0, { label: '隐患内容', prop: 'warnLevelName' })
          // copyColumn.pop()
          const str = {}
          copyColumn.forEach((item) => {
            str[item.prop] = item.label
          })
          const params = this.searchParams
          if (params.checkDt && params.checkDtEnd) {
            params.checkDt = new Date(params.checkDt)
            params.checkDtEnd = new Date(params.checkDtEnd)
          }
          if (params.lastCheckTime && params.lastCheckTimeEnd) {
            params.lastCheckTime = new Date(params.lastCheckTime)
            params.lastCheckTimeEnd = new Date(params.lastCheckTimeEnd)
          }
          gasCheckBillExportAgain({
            paramInfo: _this._getQuery(params),
            kv: str // 表格列
          }).then((res) => {
            window.open(`${this.exportDomain}/page/export/frame?key=${res.data}`, '_blank')
          })
        })
      },
      // 安检单详情
      async openOrderInfo(row, type) {
        const r = JSON.parse(JSON.stringify(row))
        await this.$refs.securityOrderInfo.open(r, type)
      },
      async openOrderExamine(row) {
        await this.$refs.exchange.open(row)
      },
      async scoresMerge() {},
      async infoCircul() {},
      search() {
        this.$refs.lbTable.fetch({ currentPage: 1 })
      },
      reset() {
        this.$refs.form.resetFields()
      },
      handleSelectionChange(val) {
        this.multipleSelection = val
        // disabledLimit
        const length = this.multipleSelection.length
        if (length === 0) {
          this.disabledLimit = true
          this.disabled = true
          this.recheckDisabled = true
        }
        if (length >= 1) {
          const stastus = this.multipleSelection.map((item) => item.isClosed)
          const recheckStatus = this.multipleSelection.map((item) => item.recheckStatus)
          this.disabled = false
          this.recheckDisabled = false
          if (stastus.indexOf(0) > -1 && stastus.indexOf(1) > -1) {
            this.disabledLimit = true
          } else {
            this.disabledLimit = false
          }
          recheckStatus.forEach((item) => {
            if (item !== 1) {
              this.disabled = true
            }
            if (item !== 1 && item !== 3) {
              this.recheckDisabled = true
            }
          })
        }
      },
      getQuery() {
        const query = { ...this._getQuery(this.query) }
        console.log('this.date', this.date)
        if (this.date && this.date.length === 2) {
          query[this.timeType] = this.date[0] + ' 00:00:00'
          query[`${this.timeType}End`] = this.date[1] + ' 00:00:00'
          const diff = moment(this.date[1]).diff(moment(this.date[0]), 'days')
          if (diff > 93) {
            this.$message.error('选择时间条件相差不能超过3个月')
            return
          }
        }
        return query
      },
      // 自适应表格列宽
      flexColumnWidth() {
        this.$nextTick(() => {
          let max = 0
          const actionColDom = document.getElementsByClassName('action-col')
          for (let i = 0; i < actionColDom.length; i++) {
            if (actionColDom[i].tagName === 'TD') {
              let width = 20
              const linkDom = actionColDom[i].childNodes[0].childNodes[0].childNodes
              linkDom.forEach((it) => {
                width += it.offsetWidth + 10
              })
              if (width > max) max = width
            }
          }
          this.actionColWidth = max > 60 ? max - 10 : 50
        })
      },
      limitOrder() {
        if (this.multipleSelection[0].isClosed === 0) {
          this.$prompt(`请填写限制下单原因！限制下单后，用户将无法下单，请及时处理！`, '操作提示', {
            type: 'warning',
            showInput: true,
            inputPlaceholder: '请输入内容',
            inputType: 'textarea',
            rows: 3,
            inputValidator: (value) => {
              if (!value) {
                return '请填写备注！'
              }
            },
            inputErrorMessage: '请填写备注！'
          }).then(({ value }) => {
            // todo

            let recheckbillCodes = this.multipleSelection.map((item) => item.recheckbillCode)
            recheckbillCodes = recheckbillCodes.join(',')
            restrictOrders({ codes: recheckbillCodes, status: 1, closeRemark: value || '' }).then(res => {
              if (res.status === 200) {
                this.$message('操作成功')
                this.$refs.lbTable.fetch({ currentPage: 1 })
              }
            })
          })
        } else {
          this.$prompt(`限制将取消，用户恢复下单权`, '操作提示', {
            type: 'warning',
            showInput: true,
            inputPlaceholder: '请输入内容',
            inputType: 'textarea',
            rows: 3
          }).then(({ value }) => {
            let recheckbillCodes = this.multipleSelection.map((item) => item.recheckbillCode)
            recheckbillCodes = recheckbillCodes.join(',')
            restrictOrders({ codes: recheckbillCodes, status: 0, closeRemark: value || '' }).then(res => {
              if (res.status === 200) {
                this.$message('操作成功')
                this.$refs.lbTable.fetch({ currentPage: 1 })
              }
            })
          })
        }
      },
      // 转派
      transfer() {
        const recheckbillCodes = this.multipleSelection.map((item) => item.recheckbillCode)
        const recheckStatus = this.multipleSelection.map((item) => item.recheckStatus)
        const checkIds = this.multipleSelection.map((item) => item.checkId)
        let codes = []
        for (let i = 0; i < recheckbillCodes.length; i++) {
          const code = recheckbillCodes[i] + ';' + recheckStatus[i]
          codes.push(code)
        }
        codes = codes.join(',')
        if (this.multipleSelection.length === 1) {
          this.$refs.transfer.open(codes, checkIds, this.multipleSelection[0])
        } else {
          this.$refs.transfer.open(codes, checkIds)
        }
      },
      refresh() {
        this.$refs.lbTable.fetch({ currentPage: 1 })
      },
      // 打开客户详情弹窗
      async openCsmDetail(row) {
        await this.$refs.csmDetail.open(row, true)
      }
    }
  }
</script>

<style lang="scss" scoped>
.form {
  .el-radio {
    margin-right: 15px;
  }
}
.el-form-item .el-form-item {
  margin-bottom: 0;
}
.merge-item {
  /deep/ .el-form-item__content {
    display: flex;
  }
}
.btn-group {
  display: flex;
  justify-content: flex-start;
}
</style>
